// 2013-9-15下午03:16:24  net.betou.trade.main.dao.impl.ConfigDaoImpl.java

package net.betou.trade.main.dao.impl;

import net.betou.common.hibernate3.Finder;
import net.betou.common.hibernate3.HibernateBaseDao;
import net.betou.common.page.Pagination;
import net.betou.trade.entity.main.Config;
import net.betou.trade.main.dao.ConfigDao;

import org.springframework.stereotype.Repository;

/**
 * 
 * @author 叶装装
 */
@Repository
public class ConfigDaoImpl extends HibernateBaseDao< Config, Integer > implements ConfigDao{

	public Config deleteById( Integer id ) {
		Config bean = get( id );
		if( bean != null ){
			getSession( ).delete( bean );
		}

		return bean;
	}

	public Config findById( Integer id ) {
		Config bean = get( id );
		return bean;
	}

	public Config save( Config bean ) {
		getSession( ).save( bean );
		return bean;
	}

	public Config findByDefault( ){
		String hql = "from Config bean where bean.configDefault=?";
		return ( Config ) findUniqueCacheable( hql, true );
	}
	
	public Config findByAdmin( Integer adminId ){
		String hql = "from Config bean where bean.admin.id=?";
		return ( Config ) findUniqueCacheable( hql, adminId ); 
	}
	
	public Pagination getPage( String searchProperty, String searchValue, String orderProperty, String orderDirection, String filterStatus, int pageNo, int pageSize ){
		
		Finder f = Finder.create( " from Config bean where 1=1 " );
		
		createFilter( f, filterStatus );
		createSearch( f, searchProperty, searchValue );
		createOrder( f, orderProperty, orderDirection, "id" );
		
		return find( f, pageNo, pageSize );
	}
	
	@Override
	protected Class< Config > getEntityClass( ) {
		return Config.class;
	}

}
